/**
 * Created by haoli on 3/13/14.
 */
var QappVoteModel = require("../model/QappVoteModel");
var async = require("async");
//exports.getQappVoteById = function( require,fun ){
//    qapp_id = require.query.qapp_id;
//    sqlStr = "select * from "+ table + " where id = " + qapp_id;
//    console.log( sqlStr );
//    mysql.query( sqlStr, fun );
//}
//
//exports.getQappVoteList = function(require,fun){
//
//}


module.exports = function( req,res ){
//    this.req = req ;
//    this.res = res;

    voteModel = new QappVoteModel({})

    this.getQappVoteList = function(){
        sqlStr = "select * from " + table;

        mysql.query( sqlStr,function(err,result){
            if( !err ){
                res.send( result );
            }else{
                res.send( !err );
            }
        } );
    };

    this.getQappVoteById = function(){
        voteModel.id = req.query.qapp_id;

        async.waterfall([
            function(callback){
                voteModel.getQappVoteById(function(err,result){
                        callback( null,result );//callback(err,result);
                })
            },
            function(callbackresult,callback){
                QappVoteOptionModel = require("../model/QappVoteOptionModel");
                optionModel = new QappVoteOptionModel({'vote_id':voteModel.id});
                optionModel.getVoteOptionByVoteId( function(e,r ){
                        callbackresult[0]['voteoption'] = r;
                        console.log( r );
                        callback(e,callbackresult);
                })
            }
        ],function(err,result){
            res.send(result);
        })
    };
}